package com.qf.staff.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.common.base.result.RespResult;
import com.qf.staff.common.qo.CategoryQo;
import com.qf.staff.common.vo.CategoryVo;
import com.qf.staff.service.CategoryService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "商品类型管理Api")
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Resource
    CategoryService categoryService;

    @ApiOperation("查询所有商品类型")
    @ApiImplicitParams(
            {@ApiImplicitParam(name = "page", value = "页码"),
                    @ApiImplicitParam(name = "size", value = "条数"),
                    @ApiImplicitParam(name = "productName", value = "商品类型名称"),
            })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})

    @GetMapping("/list")
    public RespResult<IPage<CategoryVo>> list(@RequestParam(defaultValue = "1") int page,
                                              @RequestParam(defaultValue = "10") int size,
                                              CategoryQo categoryQo
    ) {
        return RespResult.success(categoryService.list(page, size, categoryQo));
    }


    @ApiOperation("查询所有商品类型及下面商品")
    @ApiImplicitParams(
            {@ApiImplicitParam(name = "page", value = "页码"),
                    @ApiImplicitParam(name = "size", value = "条数"),
                    @ApiImplicitParam(name = "productName", value = "商品类型名称"),
            })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})

    @GetMapping("/list/sub")
    public RespResult<IPage<CategoryVo>> listSub(@RequestParam(defaultValue = "1") int page,
                                                 @RequestParam(defaultValue = "10") int size,
                                                 CategoryQo categoryQo
    ) {
        return RespResult.success(categoryService.listSub(page, size, categoryQo));
    }

    @ApiOperation("根据id修改status为0是删除商品类型")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "商品类型id")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @DeleteMapping("/remove")
    public RespResult<Integer> remove(CategoryQo categoryQo) {
        return RespResult.success(categoryService.delete(categoryQo));
    }

    @ApiOperation("根据ID修改商品类型信息")
    @ApiResponses({@ApiResponse(code = 200, message = "成功"),})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "productName", value = "商品类型名称"),
            @ApiImplicitParam(name = "category_id", value = "商品类型上级")
    })
    @PutMapping("/modify")
    public RespResult<Integer> modify(CategoryQo categoryQo) {
        return RespResult.success(categoryService.modify(categoryQo));
    }

    @ApiOperation("根据id修改status为0是批量删除商品类型")
    @ApiImplicitParams({@ApiImplicitParam(name = "deptId", value = "部门id")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @DeleteMapping("/remove/all/{status}")
    public int removeAll(@RequestBody List<Integer> ids, @PathVariable("status") int status) {
        return categoryService.deleteAll(ids, status);
    }

    @ApiOperation("添加商品类型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "productName", value = "商品类型名称"),
            @ApiImplicitParam(name = "categoryId", value = "商品类型上级"),
            @ApiImplicitParam(name = "status", value = "商品类型状态"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @PostMapping("/add")
    public RespResult<Integer> add(CategoryQo categoryQo) {
        return RespResult.success(categoryService.add(categoryQo));
    }
}
